#include "Box2DMap.h"

/* get parameters on shapes joints and bodies */
bool getParam(char* param, b2Body* x, long& ac, t_atom* av) { // pass param, ac to fill, and av to fill
	
	if(EQUALS(param,"position")) {
		RETURN_VEC_M2P(ac,av,param,x->GetPosition());
	} else if(EQUALS(param,"angle")) {
		RETURN_FLOAT(ac,av,param,x->GetAngle());
	} else if(EQUALS(param,"worldcenter")) {
		RETURN_VEC_M2P(ac,av,param,x->GetWorldCenter());
	} else if(EQUALS(param,"localcenter")) {
		RETURN_VEC_M2P(ac,av,param,x->GetLocalCenter());
	} else if(EQUALS(param,"linearvelocity")) {
		RETURN_VEC_M2P(ac,av,param,x->GetLinearVelocity());
	} else if(EQUALS(param,"angularvelocity")) {
		RETURN_FLOAT(ac,av,param,x->GetAngularVelocity());
	} else if(EQUALS(param,"mass")) {
		RETURN_FLOAT(ac,av,param,x->GetMass());
	} else if(EQUALS(param,"inertia")) {
		RETURN_FLOAT(ac,av,param,x->GetInertia());
	} else if(EQUALS(param,"isbullet")) {
		RETURN_BOOL(ac,av,param,x->IsBullet());
	} else if(EQUALS(param,"isstatic")) {
		RETURN_BOOL(ac,av,param,x->IsStatic());
	} else if(EQUALS(param,"isdynamic")) {
		RETURN_BOOL(ac,av,param,x->IsDynamic());
	} else if(EQUALS(param,"isfrozen")) {
		RETURN_BOOL(ac,av,param,x->IsFrozen());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
} 
bool getParam(char* param, b2CircleShape* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"localposition")) {
		RETURN_VEC_M2P(ac,av,param,x->GetLocalPosition());
	} else if(EQUALS(param,"radius")) {
		RETURN_FLOAT_M2P(ac,av,param,x->GetRadius());
	/* base class below */
	} else if(EQUALS(param,"issensor")) {
		RETURN_BOOL(ac,av,param,x->IsSensor());
	
	/* filter data */
	} else if(EQUALS(param,"maskbits")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().maskBits);		
	} else if(EQUALS(param,"categorybits")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().categoryBits);		
	} else if(EQUALS(param,"groupindex")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().groupIndex);		

	} else if(EQUALS(param,"friction")) {
		RETURN_FLOAT(ac,av,param,x->GetFriction());
	} else if(EQUALS(param,"restitution")) {
		RETURN_FLOAT(ac,av,param,x->GetRestitution());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
} // pass param, ac to fill, and av to fill

bool getParam(char* param, b2PolygonShape* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"centroid")) {
		RETURN_VEC_M2P(ac,av,param,x->GetCentroid());
	} else if(EQUALS(param,"vertexcount")) {
		RETURN_LONG(ac,av,param,x->GetVertexCount());
	/* base class below */
	} else if(EQUALS(param,"issensor")) {
		RETURN_BOOL(ac,av,param,x->IsSensor());
	/* filter data */
	} else if(EQUALS(param,"maskbits")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().maskBits);		
	} else if(EQUALS(param,"categorybits")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().categoryBits);		
	} else if(EQUALS(param,"groupindex")) {
		RETURN_LONG(ac,av,param,x->GetFilterData().groupIndex);		

	} else if(EQUALS(param,"friction")) {
		RETURN_FLOAT(ac,av,param,x->GetFriction());
	} else if(EQUALS(param,"restitution")) {
		RETURN_FLOAT(ac,av,param,x->GetRestitution());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}



} // pass param, ac to fill, and av to fill

bool getParam(char* param, b2RevoluteJoint* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else if(EQUALS(param,"jointangle")) {
		RETURN_FLOAT(ac,av,param,x->GetJointAngle());
	} else if(EQUALS(param,"jointspeed")) {
		RETURN_FLOAT(ac,av,param,x->GetJointSpeed());
	} else if(EQUALS(param,"islimitenabled")) {
		RETURN_BOOL(ac,av,param,x->IsLimitEnabled());
	} else if(EQUALS(param,"lowerlimit")) {
		RETURN_FLOAT(ac,av,param,x->GetLowerLimit());
	} else if(EQUALS(param,"upperlimit")) {
		RETURN_FLOAT(ac,av,param,x->GetUpperLimit());
	} else if(EQUALS(param,"ismotorenabled")) {
		RETURN_BOOL(ac,av,param,x->IsMotorEnabled());
	} else if(EQUALS(param,"motorspeed")) {
		RETURN_FLOAT(ac,av,param,x->GetMotorSpeed());
	} else if(EQUALS(param,"motortorque")) {
		RETURN_FLOAT(ac,av,param,x->GetMotorTorque());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}


} // pass param, ac to fill, and av to fill
bool getParam(char* param, b2DistanceJoint* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

} // pass param, ac to fill, and av to fill
bool getParam(char* param, b2PrismaticJoint* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else if(EQUALS(param,"jointtranslation")) {
		RETURN_FLOAT(ac,av,param,x->GetJointTranslation());
	} else if(EQUALS(param,"jointspeed")) {
		RETURN_FLOAT(ac,av,param,x->GetJointSpeed());
	} else if(EQUALS(param,"islimitenabled")) {
		RETURN_BOOL(ac,av,param,x->IsLimitEnabled());
	} else if(EQUALS(param,"lowerlimit")) {
		RETURN_FLOAT(ac,av,param,x->GetLowerLimit());
	} else if(EQUALS(param,"upperlimit")) {
		RETURN_FLOAT(ac,av,param,x->GetUpperLimit());
	} else if(EQUALS(param,"ismotorenabled")) {
		RETURN_BOOL(ac,av,param,x->IsMotorEnabled());
	} else if(EQUALS(param,"motorspeed")) {
		RETURN_FLOAT(ac,av,param,x->GetMotorSpeed());
	} else if(EQUALS(param,"motorforce")) {
		RETURN_FLOAT(ac,av,param,x->GetMotorForce());
	} else {
		error("Unknown parameter");
		return false;
	}


} // pass param, ac to fill, and av to fill
bool getParam(char* param, b2PulleyJoint* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else if(EQUALS(param,"groundanchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetGroundAnchor1());
	} else if(EQUALS(param,"groundanchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetGroundAnchor2());
	} else if(EQUALS(param,"length1")) {
		RETURN_FLOAT_M2P(ac,av,param,x->GetLength1());
	} else if(EQUALS(param,"length2")) {
		RETURN_FLOAT_M2P(ac,av,param,x->GetLength2());
	} else if(EQUALS(param,"ratio")) {
		RETURN_FLOAT(ac,av,param,x->GetRatio());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

} // pass param, ac to fill, and av to fill
bool getParam(char* param, b2GearJoint* x, long& ac, t_atom* av) { 
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else if(EQUALS(param,"ratio")) {
		RETURN_FLOAT(ac,av,param,x->GetRatio());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
	
} // pass param, ac to fill, and av to fill
bool getParam(char* param, b2MouseJoint* x, long& ac, t_atom* av) {
	if(EQUALS(param,"anchor1")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor1());
	} else if(EQUALS(param,"anchor2")) {
		RETURN_VEC_M2P(ac,av,param,x->GetAnchor2());
	/* base class below */
	} else if(EQUALS(param,"reactionforce")) {
		RETURN_VEC(ac,av,param,x->GetReactionForce());
	} else if(EQUALS(param,"reactiontorque")) {
		RETURN_FLOAT(ac,av,param,x->GetReactionTorque());
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
} // pass param, ac to fill, and av to fill

// set parameters on shapes, joints, and bodies 
bool setParameter(char* param, b2Body* x, long ac, t_atom* av) { 
	
	if(EQUALS(param,"massdata")) {
			if(ac == 4) {
			
				b2MassData massData;
				massData.mass = atom_getfloat(av);
				massData.center = b2Vec2(atom_getfloat(av+1), atom_getfloat(av+2)); // local coords
				massData.I = atom_getfloat(av+3);
			
				x->SetMass(&massData);
				return true;
			
			} else {
				return false;
			}

	} else if(EQUALS(param,"mass")) {
		
		if(ac == 1) {
			b2MassData massData;
			massData.mass = atom_getfloat(av);
			massData.I = x->GetInertia();
			massData.center = x->GetLocalCenter();	
			x->SetMass(&massData);
			return true;
		} else {
			error("need mass");
			return false;
		}
	
	} else if(EQUALS(param,"intertia")) {
		if(ac == 1) {
			b2MassData massData;
			massData.mass = x->GetMass();
			massData.I = atom_getfloat(av);
			massData.center = x->GetLocalCenter();	
			x->SetMass(&massData);
			return true;
		} else {
			error("need intertia");
			return false;
		}		
		
	} else if(EQUALS(param,"centerofmass")) {
		if(ac == 2) {
			b2MassData massData;
			massData.mass = x->GetMass();
			massData.I = x->GetInertia();
			massData.center = b2Vec2(P2M(atom_getfloat(av)),P2M(atom_getfloat(av+1)));	
			x->SetMass(&massData);
			return true;
		} else {
			error("need x, y");
			return false;
		}		
	
	} else if(EQUALS(param,"massfromshapes")) {
		x->SetMassFromShapes();

	} else if(EQUALS(param,"angle")) {
		if(ac == 1) {
			b2Vec2 pos = x->GetWorldCenter();
			return x->SetXForm(pos,atom_getfloat(av));
		} else {
			error("need angle");
		}

				
	} else if(EQUALS(param,"position")) {
	
		if(ac == 2) { 
			b2Vec2 pos = b2Vec2(P2M(atom_getfloat(av)), P2M(atom_getfloat(av+1))); 
			float angle = x->GetAngle(); // use same angle
			return x->SetXForm(pos,angle);
		} else {
			error("need x, y");
		}
				
	} else if(EQUALS(param,"xform")) {
		if(ac == 3) {
			
			b2Vec2 pos = b2Vec2(P2M(atom_getfloat(av)), P2M(atom_getfloat(av+1))); 
			return x->SetXForm(pos,atom_getfloat(av+2));
		
		} else {
			error("need x, y, angle");
			return false;
		}

	} else if(EQUALS(param,"linearvelocity")) {
		SET_VEC_FUNC_P2M(ac,av,x->SetLinearVelocity);
	} else if(EQUALS(param,"angularvelocity")) {
		SET_FLOAT_FUNC(ac,av,x->SetAngularVelocity);
	} else if(EQUALS(param,"isbullet")) {
		SET_FUNC_BOOL(ac,av,x->SetBullet);
	} else if(EQUALS(param,"allowsleep")) {
		SET_FUNC_BOOL(ac,av,x->AllowSleeping);
	} else if(EQUALS(param,"wakeup")) {
		x->WakeUp();
	} else if(EQUALS(param,"puttosleep")) {
		x->PutToSleep();
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

}

bool setParameter(char* param, b2CircleShape* x, long ac, t_atom* av){ 
	
	/* filter data */
	/*
	if(EQUALS(param,"maskbits")) {
		if(ac == 1) {
			b2FilterData fd = x->GetFilterData();
			fd.maskBits = atom_getlong(av);
			x->SetFilterData(&fd);
			return true;
		} else {
			return false;
		}
	} else if(EQUALS(param,"categorybits")) {
		if(ac == 1) {
			b2FilterData fd = x->GetFilterData();
			fd.categoryBits = atom_getlong(av);
			x->SetFilterData(&fd);
			return true;
		} else {
			return false;
		}


	} else if(EQUALS(param,"groupindex")) {
		if(ac == 1) {
			b2FilterData fd = x->GetFilterData();
			fd.groupIndex = atom_getlong(av);
			x->SetFilterData(&fd);
			return true;
		} else {
			return false;
		}
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
	*/
		error("no settable parameters to set for circle shape after creation");

}
bool setParameter(char* param, b2PolygonShape* x, long ac, t_atom* av){ 
	error("no settable parameters to set for polygon shape after creation");
}

bool setParameter(char* param, b2RevoluteJoint* x, long ac, t_atom* av){ 

	if(EQUALS(param,"enablelimit")) {
			SET_FUNC_BOOL(ac,av,x->EnableLimit);
	} else if(EQUALS(param,"setlimits")) {
		if(ac == 2) {
			x->SetLimits(atom_getfloat(av), atom_getfloat(av+1));
			return true;
		} else {
			error("needs two limits");
			return false;
		}
		
	} else if(EQUALS(param,"enablemotor")) {
			SET_FUNC_BOOL(ac,av,x->EnableMotor);
	} else if(EQUALS(param,"motorspeed")) {
		SET_FLOAT_FUNC(ac,av,x->SetMotorSpeed);
	} else if(EQUALS(param,"maxmotortorque")) {
		SET_FUNC_BOOL(ac,av,x->SetMaxMotorTorque);
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

}
bool setParameter(char* param, b2DistanceJoint* x, long ac, t_atom* av){ 
	error("no settable parameters to set for distance joint");
}
bool setParameter(char* param, b2PrismaticJoint* x, long ac, t_atom* av){ 

	if(EQUALS(param,"enablelimit")) {
			SET_FUNC_BOOL(ac,av,x->EnableLimit);
	} else if(EQUALS(param,"setlimits")) {
		if(ac == 2) {
			x->SetLimits(atom_getfloat(av), atom_getfloat(av+1));
			return true;
		} else {
			error("needs two limits");
			return false;
		}
		
	} else if(EQUALS(param,"enablemotor")) {
			SET_FUNC_BOOL(ac,av,x->EnableMotor);
	} else if(EQUALS(param,"motorspeed")) {
		SET_FLOAT_FUNC(ac,av,x->SetMotorSpeed);
	} else if(EQUALS(param,"maxmotorforce")) {
		SET_FUNC_BOOL(ac,av,x->SetMaxMotorForce);
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}


}
bool setParameter(char* param, b2PulleyJoint* x, long ac, t_atom* av){ 
	error("no settable parameters to set for pulley joint");
}
bool setParameter(char* param, b2GearJoint* x, long ac, t_atom* av){ 
	error("no settable parameters to set for gear joint");
}
bool setParameter(char* param, b2MouseJoint* x, long ac, t_atom* av){ 
	if(EQUALS(param,"target")) {
			SET_VEC_FUNC_P2M(ac,av,x->SetTarget);
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

}

				
//set parameters on DEFS, from shapes, joints and bodies 
bool setParameter(char* param, b2BodyDef& d, long ac, t_atom* av) { 

	if(EQUALS(param,"mass")) {
		SET_FLOAT(ac,av,d.massData.mass);
	} else if(EQUALS(param,"centerofmass")) {
		SET_VEC_P2M(ac,av,d.massData.center);
	} else if(EQUALS(param,"intertia")) {
		SET_FLOAT(ac,av,d.massData.I);
	} else if(EQUALS(param,"position")) {
		SET_VEC_P2M(ac,av,d.position);
	} else if(EQUALS(param,"angle")) {
		SET_FLOAT(ac,av,d.angle);
	} else if(EQUALS(param,"lineardamping")) {
		SET_FLOAT(ac,av,d.linearDamping);
	} else if(EQUALS(param,"angulardamping")) {
		SET_FLOAT(ac,av,d.angularDamping);
	} else if(EQUALS(param,"allowsleep")) {
		SET_BOOL(ac,av,d.allowSleep);	
	} else if(EQUALS(param,"issleeping")) {
		SET_BOOL(ac,av,d.isSleeping);
	} else if(EQUALS(param,"fixedrotation")) {
		SET_BOOL(ac,av,d.fixedRotation);
	} else if(EQUALS(param,"isbullet")) {
		SET_BOOL(ac,av,d.isBullet);
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
}

bool setParameter(char* param, b2CircleDef& d,long ac, t_atom* av) { 

	/////////=---- BASE CLASS
	if(EQUALS(param,"friction")) {
		SET_FLOAT(ac,av,d.friction);
	} else if(EQUALS(param,"restitution")) {
		SET_FLOAT(ac,av,d.restitution);
	} else if(EQUALS(param,"density")) {
		SET_FLOAT(ac,av,d.density);
	} else if(EQUALS(param,"issensor")) {
		SET_BOOL(ac,av,d.isSensor);

	/* shape filtering */
	} else if(EQUALS(param,"groupindex")) {
		SET_LONG(ac,av,d.filter.groupIndex);
	} else if(EQUALS(param,"categorybits")) {
		SET_LONG(ac,av,d.filter.categoryBits);
	} else if(EQUALS(param,"maskbits")) {
		SET_LONG(ac,av,d.filter.maskBits);
		
		
	/////////=---- CIRLC CLASS
	} else if(EQUALS(param,"radius")) {
		SET_FLOAT_P2M(ac,av,d.radius);	
	} else if(EQUALS(param,"localposition")) {
		SET_VEC_P2M(ac,av,d.localPosition);
	} else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
	
}

bool setParameter(char* param, b2PolygonDef& d,long ac, t_atom* av,std::vector<b2Vec2>* vertices){//, vector <b2Vec2>* polyPoints) { 
	/////////=---- BASE CLASS
	if(EQUALS(param,"friction")) {
		SET_FLOAT(ac,av,d.friction);
	} else if(EQUALS(param,"restitution")) {
		SET_FLOAT(ac,av,d.restitution);
	} else if(EQUALS(param,"density")) {
		SET_FLOAT(ac,av,d.density);
	} else if(EQUALS(param,"isSensor")) {
		SET_BOOL(ac,av,d.isSensor);
	
	/* shape filtering */
	} else if(EQUALS(param,"groupindex")) {
		SET_LONG(ac,av,d.filter.groupIndex);
	} else if(EQUALS(param,"categorybits")) {
		SET_LONG(ac,av,d.filter.categoryBits);
	} else if(EQUALS(param,"maskbits")) {
		SET_LONG(ac,av,d.filter.maskBits);


		
	} else if(EQUALS(param,"vertex")) {
	
	/*
		if(d.vertexCount >= b2_maxPolygonVertices) {
				error("Your polygon has too many vertices.");
				return false;
		}
	*/
	
		if(ac == 2) { // make sure there are an even number of vertices
	
			
			
			
			//d.vertices[d.vertexCount] = b2Vec2(P2M(atom_getfloat(av)),P2M(atom_getfloat(av+1)));
			//d.vertexCount++;
			
			vertices->push_back( b2Vec2(P2M(atom_getfloat(av)),P2M(atom_getfloat(av+1))));
			
			return true;
			

		} else {
			error("Need x, y vertex.");
			return false;
		}	
	
	/////////=---- POLY CLASS
	
	} //else if(EQUALS(param,"vertices")) {
	/*
			if((ac % 2) == 0) { // make sure there are an even number of vertices
			long vc = ac / 2; // vertext count
			if(vc >= b2_maxPolygonVertices) {
				error("Your polygon has too many vertices.");
				return false;
			}
			
			d.vertexCount = vc;
			int argCount = 0;
			*/
			/* TODO: IF THIS IS NOT A SIMPLE (NON_CROSSOVER) CCW CONVEX POLYGON, the program will probably crash and burn */
			/* PERHAPS IMPLEMENT A CONVEX HULL TEST AND THROW OUT VERTICIES THAT ARE NO GOOD ... OR REJECT THE VERTICES? */
			/* http://www.qhull.org/ use this? */
			/*
			for(int i = vc; i == -1; --i) {
				d.vertices[i] = b2Vec2(P2M(atom_getfloat(av+(argCount++))),
									   P2M(atom_getfloat(av+(argCount++)))
									   );
			}
			
			return true;
		
		} else {
			error("Uneven number of vertices.");
			false;
		}
	*/
	//} else {
	else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
	
}

bool setParameter(char* param, b2DistanceJointDef& d,long ac, t_atom* av) { 
	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"localanchor1")) {
		SET_VEC_P2M(ac,av,d.localAnchor1);
	} else if(EQUALS(param,"localanchor2")) {
		SET_VEC_P2M(ac,av,d.localAnchor2);
	} else if(EQUALS(param,"length")) {
		SET_FLOAT(ac,av,d.length);
	} else if(EQUALS(param,"frequencyhz")) {
		SET_FLOAT(ac,av,d.frequencyHz);
	} else if(EQUALS(param,"dampingratio")) {
		SET_BOOL(ac,av,d.dampingRatio);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}



}

bool setParameter(char* param, b2GearJointDef& d,long ac, t_atom* av){ 
	
	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"ratio")) {
		SET_FLOAT(ac,av,d.ratio);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}



}

bool setParameter(char* param, b2MouseJointDef& d,long ac, t_atom* av){ 

/////////=---- BASE CLASS

	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"target")) {
		SET_VEC_P2M(ac,av,d.target);
	} else if(EQUALS(param,"maxforce")) {
		SET_FLOAT(ac,av,d.maxForce);
	} else if(EQUALS(param,"frequencyhz")) {
		SET_FLOAT(ac,av,d.frequencyHz);
	} else if(EQUALS(param,"dampingratio")) {
		SET_BOOL(ac,av,d.dampingRatio);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}

}

bool setParameter(char* param, b2PrismaticJointDef& d,long ac, t_atom* av){ 
/////////=---- BASE CLASS

	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"localanchor1")) {
		SET_VEC_P2M(ac,av,d.localAnchor1);
	} else if(EQUALS(param,"localanchor2")) {
		SET_VEC_P2M(ac,av,d.localAnchor2);
	} else if(EQUALS(param,"localaxis")) {
		SET_VEC_P2M(ac,av,d.localAxis1);
	} else if(EQUALS(param,"referenceangle")) {
		SET_FLOAT(ac,av,d.referenceAngle);
	} else if(EQUALS(param,"enablelimit")) {
		SET_BOOL(ac,av,d.enableLimit);
	} else if(EQUALS(param,"lowertranslation")) {
		SET_FLOAT(ac,av,d.lowerTranslation);
	} else if(EQUALS(param,"uppertranslation")) {
		SET_FLOAT(ac,av,d.upperTranslation);
	} else if(EQUALS(param,"enablemotor")) {
		SET_BOOL(ac,av,d.enableMotor);
	} else if(EQUALS(param,"maxmotorforce")) {
		SET_FLOAT(ac,av,d.maxMotorForce);
	} else if(EQUALS(param,"motorspeed")) {
		SET_FLOAT(ac,av,d.motorSpeed);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}


}

bool setParameter(char* param, b2PulleyJointDef& d,long ac, t_atom* av){ 
	

/////////=---- BASE CLASS

	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"groundanchor1")) {
		SET_VEC_P2M(ac,av,d.groundAnchor1);
	} else if(EQUALS(param,"groundanchor2")) {
		SET_VEC_P2M(ac,av,d.groundAnchor2);
	} else if(EQUALS(param,"localanchor1")) {
		SET_VEC_P2M(ac,av,d.localAnchor1);
	} else if(EQUALS(param,"localanchor2")) {
		SET_VEC_P2M(ac,av,d.localAnchor2);
	} else if(EQUALS(param,"length1")) {
		SET_FLOAT(ac,av,d.length1);
	} else if(EQUALS(param,"maxlength1")) {
		SET_FLOAT(ac,av,d.maxLength1);
	}else if(EQUALS(param,"length2")) {
		SET_FLOAT(ac,av,d.length2);
	} else if(EQUALS(param,"maxlength2")) {
		SET_FLOAT(ac,av,d.maxLength2);
	} else if(EQUALS(param,"ratio")) {
		SET_FLOAT(ac,av,d.ratio);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
}

bool setParameter(char* param, b2RevoluteJointDef& d,long ac, t_atom* av){ 

/////////=---- BASE CLASS

	if(EQUALS(param,"collideConnected")) {
		SET_BOOL(ac,av,d.collideConnected);
	} else 


/// other
	if(EQUALS(param,"localanchor1")) {
		SET_VEC_P2M(ac,av,d.localAnchor1);
	} else if(EQUALS(param,"localanchor2")) {
		SET_VEC_P2M(ac,av,d.localAnchor2);
	} else if(EQUALS(param,"upperangle")) {
		SET_FLOAT(ac,av,d.upperAngle);
	} else if(EQUALS(param,"lowerangle")) {
		SET_FLOAT(ac,av,d.lowerAngle);
	} else if(EQUALS(param,"enablemotor")) {
		SET_BOOL(ac,av,d.enableMotor);
	} else if(EQUALS(param,"enablelimit")) {
		SET_BOOL(ac,av,d.enableLimit);
	} else if(EQUALS(param,"motorspeed")) {
		SET_FLOAT(ac,av,d.upperAngle);
	} else if(EQUALS(param,"maxmotortorque")) {
		SET_FLOAT(ac,av,d.maxMotorTorque);
	}  else {
		error("Unknown parameter \"%s\"",param);
		return false;
	}
}